package org.ycx.upms.web.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.session.events.SessionExpiredEvent;
import org.springframework.stereotype.Component;
import org.ycx.upms.common.constants.SecurityConstants;

/**
 * Created by 杨 on 2017-06-05.
 */
@Component
public class SessionExpiredEventListener implements ApplicationListener<SessionExpiredEvent> {


    @Autowired
    private RedisTemplate redisTemplate;


    @Override
    public void onApplicationEvent(SessionExpiredEvent sessionExpiredEvent) {
        if(redisTemplate.keys(SecurityConstants.ONLINE_USER+"-"+sessionExpiredEvent.getSessionId()).size() > 0){
            redisTemplate.delete(SecurityConstants.ONLINE_USER+"-"+sessionExpiredEvent.getSessionId());
        }
    }
}
